 package com.oanda.blackberry.restapi;
 
 import com.oanda.blackberry.util.StringUtils;
 
 public class Price
 {
   Symbol symbol;
   double price;
 
   public Price(Symbol symbol, double price)
   {
     this.symbol = symbol;
     this.price = price;
   }
 
   public double getPrice() {
     return this.price;
   }
 
   public Symbol getSymbol() {
     return this.symbol;
   }
 
   public String getPippetteString() {
     if (this.symbol.getPipetteLength() > 0)
     {
       String s = StringUtils.formatDouble(this.price, this.symbol.getPrecision());
       return s.substring(s.length() - this.symbol.getPipetteLength());
     }
     return "";
   }
 
   private String removeDot(String s)
   {
     StringBuffer sb = new StringBuffer();
     char[] c = s.toCharArray();
     int i = 0;
     if (s.indexOf('.') < 0)
       i++;
     for (; (c != null) && (i < c.length); i++) {
       if (c[i] != '.')
         sb.append(c[i]);
     }
     return sb.toString();
   }
 
   public String getMainPriceString() {
     try {
       int MAX_MAIN = 2;
 
       String s = StringUtils.formatDouble(this.price, this.symbol.getPrecision());
 
       int i = s.indexOf(".");
 
       if (this.symbol.getPipetteLength() > 0)
       {
         if (s.length() > this.symbol.getPipetteLength() + MAX_MAIN) {
           int i1 = s.length() - this.symbol.getPipetteLength() - MAX_MAIN;
           int i2 = s.length() - this.symbol.getPipetteLength();
 
           String t = s.substring(i1, i2);
 
           if (t.indexOf('.') > -1) {
             MAX_MAIN = 3;
             if (s.length() > this.symbol.getPipetteLength() + MAX_MAIN) {
               int y1 = s.length() - this.symbol.getPipetteLength() - MAX_MAIN;
               int y2 = s.length() - this.symbol.getPipetteLength();
 
               t = s.substring(y1, y2);
             }
           }
           return t;
         }
 
         return s;
       }
       return s.substring(i + 1);
     }
     catch (NumberFormatException ne) {
       return "m"; } catch (IndexOutOfBoundsException i) {
     }
     return "M";
   }
 
   public String getBaseString()
   {
     try
     {
       String s = StringUtils.formatDouble(this.price, this.symbol.getPrecision());
 
       int i = s.length() - getMainPriceString().length() - getPippetteString().length();
       if (i < s.length()) {
         return s.substring(0, i);
       }
       return s;
     }
     catch (NumberFormatException ne) {
       return "b"; } catch (IndexOutOfBoundsException i) {
     }
     return "B";
   }
 
   public String getPriceAsString()
   {
     String s = StringUtils.formatDouble(this.price, this.symbol.getPrecision());
     return s;
   }
 
   public String toString() {
     return getPriceAsString();
   }
}

